package com.youku.adSDK.model
{
   import com.youku.adSDK.ADContext;
   import com.youku.adSDK.view.events.ADEvent;
   import com.youku.adSDK.ADConstant;
   import flash.events.Event;
   import com.youku.adSDK.model.vo.GroupData;
   import flash.net.URLLoader;
   import com.adobe.json.JSON;
   
   public class BackProxy extends ADProxy
   {
      
      public function BackProxy() {
         super();
      }
      
      public function init(param1:ADContext) : void {
         if(param1.allowBCSpecialType)
         {
            _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOAD_ERROR));
            return;
         }
         super.loadData(ADConstant.BACK_AD,ADConstant.BACK_REQUEST_BASE,param1);
      }
      
      override public function onLoaderComplete(param1:Event) : void {
         var groupData:GroupData = null;
         var e:Event = param1;
         var jstr:String = URLLoader(e.currentTarget).data;
         var obj:Object = {};
         if(jstr)
         {
            try
            {
               obj = com.adobe.json.JSON.decode(jstr);
            }
            catch(erro:Error)
            {
               trace(erro.getStackTrace());
            }
         }
         groupData = super.parseGroupData(obj);
         if(!groupData)
         {
            _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOAD_ERROR));
            return;
         }
         if(groupData.P != 2)
         {
            _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOAD_ERROR));
            return;
         }
         if(!groupData.VAL || groupData.VAL.length == 0)
         {
            _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOAD_ERROR));
            return;
         }
         _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOADED,groupData));
      }
      
      override public function onLoaderError(param1:Event) : void {
         _eventDispather.dispatchEvent(new ADEvent(ADEvent.BACK_DATA_LOAD_ERROR));
      }
   }
}
